package com.easy.activiti.mapper;



import com.easy.activiti.pojo.Act_ru_task;
import com.easy.activiti.pojo.Formdata;
import com.easy.activiti.pojo.TaskInfoExtend;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;


@Mapper
@Component
public interface ActivitiMapper {

    //读取表单
    @Select("SELECT Control_ID_,Control_VALUE_ from formdata where PROC_INST_ID_ = #{PROC_INST_ID}")
    List<HashMap<String, Object>> selectFormData(@Param("PROC_INST_ID") String PROC_INST_ID);


    //写入表单
    @Insert("insert into formdata (TASK_ID_,PROC_DEF_ID_,PROC_INST_ID_,FORM_KEY_,Control_ID_,Control_VALUE_)")
    int insertFormData(@Param("list") List<Formdata> list);

    //删除表单
    @Delete("DELETE FROM formdata WHERE PROC_DEF_ID_ = #{PROC_DEF_ID}")
    int DeleteFormData(@Param("PROC_DEF_ID") String PROC_DEF_ID);

    //获取用户名
    @Select("SELECT name,username from user")
    List<HashMap<String, Object>> selectUser();

    //测试
    @Select("select NAME_,TASK_DEF_KEY_ from act_ru_task")
    List<Act_ru_task> selectName();

    @Select("select any_value(p.PROC_INST_ID_) as PROC_INST_ID_,any_value(v.Control_ID_) as NAME_,any_value(v.Control_VALUE_) as TEXT_,any_value(v.TASK_ID_)  as TASK_ID_,any_value(p.NAME_) as  'PROC_NAME_'" +
            " from act_hi_procinst p " +
            " left join formdata v on v.PROC_INST_ID_ = p.PROC_INST_ID_ and v.TASK_ID_ in (${taskIds})"+
            " where p.PROC_INST_ID_ in (${procInstIds})")
    List<TaskInfoExtend> seletTaskVarinst(@Param("taskIds") String taskIds, @Param("procInstIds")String procInstIds);

}
